package com.sky.controller.admin;

import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 订单
 */
@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "管理端-订单接口")
public class OrderController {

    @Autowired
    private OrderService orderService;

    //--T1--【管理端】订单搜索  /admin/order/conditionSearch
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(@RequestParam Map map){
        log.info("查询订单详情：{}", map);
        PageResult pageResult=orderService.getListOrderAndDetail(map);
        return Result.success(pageResult);
    }



    //--T2--查询订单详情   /admin/order/details/{id}
    @GetMapping("/details/{id}")
    public Result<OrderVO> orderDetailId(@PathVariable Long id){
        log.info("查询订单详情：{}", id);
        OrderVO orderVO=orderService.getOrderAndDetailById(id);
        return Result.success(orderVO);
    }

    //--T3--各个状态的订单数量统计   /admin/order/statistics
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics(){
        log.info("各个状态的订单数量统计");
        OrderStatisticsVO orderStatisticsVO=orderService.getOrderStatistics();
        return Result.success(orderStatisticsVO);
    }
    //--T4--接单  /admin/order/confirm
    @PutMapping("/confirm")
    public Result sssconfirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("接单:{}",ordersConfirmDTO);
        orderService.sssconfirm(ordersConfirmDTO);
        return Result.success();
    }
    //--T5--拒单  /admin/order/rejection
    @PutMapping("/rejection")
    public Result sssrejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        log.info("拒单:{}",ordersRejectionDTO);
        orderService.sssrejection(ordersRejectionDTO);
        return Result.success();
    }
    //--T6--取消订单  /admin/order/cancel
    @PutMapping("/cancel")
    public Result ssscancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        log.info("取消订单:{}",ordersCancelDTO);
        orderService.ssscancel(ordersCancelDTO);
        return Result.success();
    }
    //--T7--派送订单  /admin/order/delivery/{id}
    @PutMapping("/delivery/{id}")
    public Result sssdelivery(@PathVariable Long id){
        log.info("派送订单:{}",id);
        orderService.sssdelivery(id);
        return Result.success();
    }
    //--T8--完成订单  /admin/order/complete/{id}
    @PutMapping("/complete/{id}")
    public Result ssscomplete(@PathVariable Long id){
        log.info("完成订单:{}",id);
        orderService.ssscomplete(id);
        return Result.success();
    }
}
